package logic

import (
	"context"
	"fmt"
	"srv/model/mysql"

	"srv/internal/svc"
	"srv/mooc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGoodsLogic {
	return &AddGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddGoodsLogic) AddGoods(in *mooc.AddGoodsRequest) (*mooc.AddGoodsResponse, error) {
	// todo: add your logic here and delete this line

	g := mysql.Goods{
		GoodsName:  in.GoodsName,
		GoodsPrice: float64(in.GoodsPrice),
	}
	err := g.Create()
	if err != nil {
		logx.Error("创建失败")
		return nil, fmt.Errorf("创建失败")
	}

	return &mooc.AddGoodsResponse{Success: true}, nil
}
